/*
 * @(#)Language.java        0.1 09/04/29
 * @version 	0.1 29 Apr 2009
 * @author 	Nguyen Thang Huy
 * 
 * Luu tru du lieu cua mot ngon ngu, doc du lieu tu XML
 */


package Data;

import XML_IO.*;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;


public class Language {
	String name;
	String base;
	String locale;
	boolean _isCurrent;
	
	public Language() {
		name = "";
		base = "";
		locale = "";
		_isCurrent = false;
	}
	
	/*
	 * Tao mot ngon ngu tu du lieu XMl
	 */
	public Language(Node node) {
		this();
		if (node.getNodeType() == Node.ELEMENT_NODE) {
			setName(XML_IO.getElementValue(node));
			NamedNodeMap attributes = node.getAttributes();
			for (int k = 0; k < attributes.getLength(); k++)
	    	{
	    		Node attribute = attributes.item(k);
	    		if (attribute.getNodeName().equals("base")) {
	    			setBase(attribute.getNodeValue());
	    		} else if (attribute.getNodeName().equals("locale")) {
	    			setLocale(attribute.getNodeValue());
	    		} else if (attribute.getNodeName().equals("isCurrent") && XML_IO.getElementValue(attribute).equals("true")) {
	    			setCurrent(true);
	    		}
	    	}
		}
	}
	
	public String getName() {
		return name;
	}
	public String getBase() {
		return base;
	}
	public String getLocale() {
		return locale;
	}
	public boolean isCurrent() {
		return _isCurrent;
	}
	public void setName(String n) {
		name = n;
	}
	
	public void setBase(String b) {
		base = b;
	}
	public void setLocale(String l) {
		locale = l;
	}
	public void setCurrent(boolean b) {
		_isCurrent = b;
	}
	
	/*
	 * Chuyen thong tin mot ngon ngu thanh XML
	 */
	public Node toXml(Document doc) {
    	Element languageElement = doc.createElement("language");
    	languageElement.appendChild(doc.createTextNode(name));
    	languageElement.setAttribute("base", base);
    	languageElement.setAttribute("locale", locale);
    	languageElement.setAttribute("isCurrent", _isCurrent + "");
    	return languageElement;
	}
}